Lesson 4 - Operators
Quiz
Why does this code produce an error?
print "84" - "23"
- It works fine and prints 61!
- The data types are mixed
- - can not be applied to strings
Why does the following code produce an error?
print 10 - "62"
- It works fine and prints -52
- The data types are mixed
- - can not be applied to strings
What will be the output of the following code?
print -1 * 2 + 3
- 1
- -5
- 5
- -2
Will the output print?
if 7 + 1 > 3 - 1:
print "hello"
- Yes, 8 is greater than 2
- No, 1 is not bigger than 3
- No, it will not compile
- No, 8 is not bigger that 31
What will this code print?
x = 2
x = x == 3
print x
- true
- false
- 3
- 2
What is the output of the following code?
print -(6 * 2 - 3) + -6 * 2 - 3
- It will cause an error
- -3
- -30
- -24
What is the output of the code below?
x = 5
print x * 2 + x * 4
- Will cause an error
- 30
- 140
- 65
Which of the following has the highest precedence?
- -10
- 10 - 2
- 10 * 2
- 10 > 2
How could the code below be fixed?
x = "87"
y = 12
if x > y:
print "hi"
- if str(x) > str(y)
- if int(x) > int(y)
- if x > int(y)
- if str(x) > y
A student needs to create a variable to store the number of cookies eaten by mr Hamflett. What would be the best variable name to use?
- cookie
- x
- mrHamflett
- numberCookiesEaten